
#include <iostream>

#include "Counter.h"

using namespace std;

class SingletonRight : private Counter<SingletonRight>
{
private:
    SingletonRight()
    {
        cout<<"object is ["<<this<<"] Do< Construction"<<endl;
    }
public:
    using Counter<SingletonRight>::howMany; // Added by jfwan

    ~SingletonRight()
    {
        cout<<"object is ["<<this<<"] Do Destruction>"<<endl;
    }

    static SingletonRight & GetSingleton()
    {
        static SingletonRight s;
        return s;
    }
    void Dosomething()
    {
        cout<<"object is ["<<this<<"] Do Something"<<endl;
    }

private: // preventions
    SingletonRight(const SingletonRight&);
    SingletonRight& operator = (const SingletonRight&);
};

class Singleton : private Counter<Singleton>
{
private:
    Singleton()
    {
        cout<<"object is ["<<this<<"] Do< Construction"<<endl;
    }
public:
    using Counter<Singleton>::howMany; // Added by jfwan

    ~Singleton()
    {
        cout<<"object is ["<<this<<"] Do Destruction>"<<endl;
    }

    static Singleton & GetSingleton()
    {
        static Singleton s;
        return s;
    }
    void Dosomething()
    {
        cout<<"object is ["<<this<<"] Do Something"<<endl;
    }
};

void CounterDemoMain()
{
    Singleton& first = Singleton::GetSingleton();

    Singleton second(first);    // 1
    Singleton third(first);     // 2

    cout << "There are " << Singleton::howMany()
         << " instances of Singleton." << endl;

    SingletonRight& first1 = SingletonRight::GetSingleton();
//如果要使用单实例，则需要把复制构造 屏蔽
  //  SingletonRight second1(first1);    // 1
  //  SingletonRight third1(first1);     // 2

    cout << "There are " << SingletonRight::howMany()
         << " instances of SingletonRight." << endl;
}
